package com.ssm.utils;

import com.ssm.pojo.UserInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserContext {

    //注入权限的service对象
    public static HttpServletRequest getRequest(){
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }
    //注入权限的service对象
    public static HttpServletResponse getResponse(){
        HttpServletResponse response = ((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse();
        return response;
    }

    public static UserInformation getUser(){
        return (UserInformation)getRequest().getSession().getAttribute("USER");
    }
}
